﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Quizz.Library.Actions;
using Quizz.Library.Filter;
using Quizz.Infrastructure;
using Quizz.Library.Controller;
using Quizz.Library.QuizzServiceReference;

namespace Quizz.Web.FrontEnd.Controllers
{
    public class UserController : BaseController
    {
        //
        // GET: /User/
        [AdminFilter]
        public ActionResult Index()
        {
            ViewData[Constants.UserListCurrent] = Session[Constants.UserListCurrent];
            ViewData[Constants.UserListKeyWord] = Session[Constants.UserListKeyWord];
            ViewData[Constants.UserListOrder] = Session[Constants.UserListOrder];
            return View();
        }


        #region Ajax methods
        [AdminFilter(IsAjax=true)]
        [HttpPost]
        public JsonResult GetUserPage([DefaultValue(0)] int page, [DefaultValue(15)] int count, [DefaultValue("Email")] string orderColumns){
            return new UserAction(this).GetUserPage(page, count, orderColumns);
        }

        [AdminFilter(IsAjax = true)]
        [HttpPost]
        public JsonResult AddUser(User user)
        {
            return new UserAction(this).AddUser(user);
        }

        [AdminFilter(IsAjax=true)]
        [HttpPost]
        public JsonResult LoadUser(long id)
        {
            return new UserAction(this).LoadUser(id);
        }

        [AdminFilter(IsAjax = true)]
        [HttpPost]
        public JsonResult DeleteUser(long id)
        {
            return new UserAction(this).DeleteUser(id);
        }

        [AdminFilter(IsAjax= true)]
        [HttpPost]
        public JsonResult EditUser(User user)
        {
            return new UserAction(this).EditUser(user);
        }
        #endregion

        #region Overide methods

        protected override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            base.OnResultExecuting(filterContext);

            CreateMenu(Constants.MenuManage);
        }

        #endregion
    }
}
